//
//  ByBlueToothListCell.m
//  laserdevice_ios
//
//  Created by pro on 16/12/19.
//  Copyright © 2016年 com.itboye. All rights reserved.
//

#import "ByBlueToothListCell.h"

@implementation ByBlueToothListCell
{
    UIView      *_bgView;
    UILabel     *_nameLabel;
    UIButton    *_connectBtn;;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = [UIColor clearColor];
        [self setupView];
    }
    return self;
}

- (void)setupView {
    
    _bgView = [[UIView alloc] init];
    _bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_bgView];
    
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.adjustsFontSizeToFitWidth = YES;
    _nameLabel.font = FONT(14);
    _nameLabel.text = @"";
    _nameLabel.textColor = [UIColor blackColor];
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    [_bgView addSubview:_nameLabel];
    
    _connectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_connectBtn setTitle:STRING(@"lianji") forState:UIControlStateNormal];
    _connectBtn.titleLabel.font = FONT(16);
    [_connectBtn setTitleColor:CJ_THEME_COLOR forState:UIControlStateNormal];
    [_connectBtn addTarget:self action:@selector(connectAction) forControlEvents:UIControlEventTouchUpInside];
    [_bgView addSubview:_connectBtn];
}

- (void)setName:(NSString *)name {
    
    _name = name;
    _nameLabel.text = _name;
}
- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    _bgView.frame = CGRectMake(10, 10, self.width - 20, self.height - 10);
    CGFloat width = [_connectBtn.titleLabel.text getSizeOfString:16].width + 5;
    _connectBtn.frame = CGRectMake(0, 0, width, _bgView.height);
    _connectBtn.right = _bgView.width - 5;
    _nameLabel.frame = CGRectMake(10, 0, 100, _bgView.height);
    _nameLabel.width = _connectBtn.left - 10 - _nameLabel.left;
}

- (void)connectAction {
    
    if (self.backAction) {
        self.backAction();
    }
}

@end
